package com.yeyks.appcontroller;

import com.yeyks.dal.domain.UserInfo;
import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.service.CashOutOrderService;
import com.yeyks.service.UserInfoService;
import com.yeyks.wxcode.service.WxLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author fuchangshuai
 * @date 2019/4/26 0026
 */
@Api(tags = "提现接口", description = "提现")
@Slf4j
@RestController
@RequestMapping(value = "/app/cash")
public class CashOutOrderController {
    @Autowired
    private UserInfoService userInfoService;
    @Autowired
    private CashOutOrderService cashOutOrderService;

//    /**
//     * 用户提现
//     *
//     * @param token
//     * @return
//     */
//    @ApiOperation(value = "用户提现", notes = "用户提现")
//    @ApiImplicitParams({
//            @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String"),
//            @ApiImplicitParam(paramType = "query", name = "code", value = "code", required = true, dataType = "String"),
//            @ApiImplicitParam(paramType = "query", name = "amount", value = "提现金额", required = true, dataType = "int"),
//            @ApiImplicitParam(paramType = "query", name = "type", value = "type(gzh(公众号),xcx(小程序)，默认gzh)", defaultValue = "gzh", dataType = "String")
//    })
//    @PostMapping(value = "/extract")
//    public ResponseEntity<?> extract(@RequestParam(name = "token") String token,
//                                     @RequestParam(name = "amount") Integer amount,
//                                     @RequestParam(name = "type", defaultValue = "gzh") String type,
//                                     @RequestParam(name = "code") String code,
//                                     HttpServletRequest request) {
//        UserInfo userInfo = userInfoService.tokenUserInfo(token);
//        String openId = userInfoService.getOpenId(userInfo, code, type);
//        return ResponseEntity.ok(AjaxResponseBody.success(openId));
//    }

    /**
     * 判断用户是否需要绑卡
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "判断用户是否需要绑卡", notes = "true需要绑卡，false不需要绑卡")
    @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String")
    @PostMapping(value = "/isBind")
    public ResponseEntity<?> isBind(@RequestParam(name = "token") String token) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        Boolean flag = userInfoService.isBind(userInfo);
        return ResponseEntity.ok(AjaxResponseBody.success(flag));
    }

    /**
     * 用户提现
     *
     * @param token
     * @return
     */
    @ApiOperation(value = "用户提现", notes = "用户提现")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "token", value = "token", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "amount", value = "提现金额", required = true, dataType = "int")
    })
    @PostMapping(value = "/extract")
    public ResponseEntity<?> extract(@RequestParam(name = "token") String token,
                                     @RequestParam(name = "amount") Integer amount) {
        UserInfo userInfo = userInfoService.tokenUserInfo(token);
        Boolean flag = cashOutOrderService.extract(userInfo, amount);
        return ResponseEntity.ok(AjaxResponseBody.success(flag));
    }

    /**
     * 提现常见问题
     *
     * @return
     */
    @ApiOperation(value = "提现常见问题", notes = "提现常见问题")
    @PostMapping(value = "/problem")
    public ResponseEntity<?> problem() {
        return ResponseEntity.ok(AjaxResponseBody.success(cashOutOrderService.problem()));
    }
}
